<%-- 
  - Author: Ismail Basha
  - Date: 4-Jan-'2012
  - Copyright Notice: TRAKHEES
  - Description: list.jsp
 --%>
<%@ include file="/WEB-INF/view/include.jsp"%>
<%@ page import="ae.pcfc.etks.online.web.*"%>

<c:choose>
	<c:when
		test='${requestScope.requestContextAttribute.locale.language == "ar"}'>
		<script language="Javascript" type="text/javascript"
			src='<c:url value="/resources/js/jqgrid/grid.locale-ar.js"/>'></script>
	</c:when>
	<c:otherwise>
		<script language="Javascript" type="text/javascript"
			src='<c:url value="/resources/js/jqgrid/grid.locale-en.js"/>'></script>
	</c:otherwise>
</c:choose>
<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/grid.base.js"/>'></script>
<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/grid.common.js"/>'></script>
<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/grid.formedit.js"/>'></script>
<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/grid.inlinedit.js"/>'></script>

<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/grid.custom.js"/>'></script>
<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/jquery.fmatter.js"/>'></script>
<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/grid.filter.js"/>'></script>
<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/grid.jqueryui.js"/>'></script>
<script language="Javascript" type="text/javascript"
	src='<c:url value="/resources/js/jqgrid/grid.import.js"/>'></script>

<script type="text/javascript">
    $.jgrid.no_legacy_api = true;
    $.jgrid.useJSON = true;
</script>

<script type="text/javascript">
	$()
			.ready(
					function() {

						$('#grid')
						.jqGrid(
								{
									datatype :'json',
									url		 :'${pageContext.request.contextPath}/user/general/manage/displayUserTable.json',
									colNames : [  '<spring:message code="label.id" />',
													'<spring:message code="label.nonclient.person.register.nameENG" />','<spring:message code="label.nonclient.person.register.nameARB" />','<spring:message code="label.nonclient.person.register.emailAddress" />', '<spring:message code="label.nonclient.person.register.status" />', '<spring:message code="label.id" />' ],
									
									colModel : [ {
										name:'UId',
										index : 'UId',
										width : 60,
										align : 'center'
									}, {
										name:'UNameEng',
										index : 'UNameEng',
										width : 400,
										align : 'center',
										sortable : true
									},{
										name:'UNameArb',
										index : 'UNameArb',
										width : 400,
										align : 'center',
										sortable : true
									} ,{
										name:'UEmail',
										index : 'UEmail',
										width : 400,
										align : 'center',
										sortable : true
									},{
										name:'UStatus',
										index : 'UStatus',
										width : 300,
										align : 'center',
										sortable : true
									},{
										name:'EUId',
										index : 'EUId',
										width : 0,
										hidden: true,
										align : 'center'
									} ],
									rowNum:10, 
									autowidth: true,
									height: 'auto', 
									 altRows:true,
							         altclass:'myAltRowClass',
									viewrecords: true,
									rowList:[10,20,30], 
									pager: jQuery('#pager'), 
									sortname: 'UNameEng', 
									viewrecords: true, 
									sortorder: "desc", 
									caption : '<spring:message code="label.menu.employees" />'
									<c:if test='${requestScope.requestContextAttribute.locale.language == "ar"}'>
									, direction:'rtl'
									</c:if>									
								}).navGrid('#pager', {
									edit : false,
									add : false,
									del : false,
									search : true,
									searchtext:'<spring:message code="label.search" />'

								});
						$("#grid").navButtonAdd('#pager',
								   {  caption:'<spring:message code="label.edit" />',
								    buttonicon:"ui-icon ui-icon-pencil",
								    onClickButton: edit,
								    position: "last",
								    title:"<spring:message code="label.edit" />",
								    cursor: "pointer"
								   }
								  );
						$("#grid").navButtonAdd('#pager',
								   {  caption:'<spring:message code="label.button.add" />',
								    buttonicon:"ui-icon ui-icon-plus",
								    onClickButton: add,
								    position: "last",
								    title:"<spring:message code="label.button.add" />",
								    cursor: "pointer"
								   }
								  );
						$("#grid").navButtonAdd('#pager',
								   {  caption:'<spring:message code="label.button.reset.password" />',
								    buttonicon:"ui-icon ui-icon-pencil",
								    onClickButton: resetPassword,
								    position: "last",
								    title:"<spring:message code="label.button.reset.password" />",
								    cursor: "pointer"
								   }
								  );						
		
		function edit(){
			var row = $('#grid').jqGrid('getGridParam','selrow');
			if(row == null)
			{
				jAlert('error','<spring:message code="error.user.select" />', '<spring:message code="label.errormessage" />');	
			}
			else{
				var userid = $('#grid').jqGrid('getCell',row,'EUId');
				window.location = "${pageContext.request.contextPath}/user/general/manage/edit.htm?userId="+userid;
			}
		}
		function add(){
			window.location = "${pageContext.request.contextPath}/user/general/manage/form.htm";
		}
		function resetPassword(){
			var row = $('#grid').jqGrid('getGridParam','selrow');
			if(row == null)
			{
				jAlert('error','<spring:message code="error.user.select" />', '<spring:message code="label.errormessage" />');	
			}
			else{
				var userid = $('#grid').jqGrid('getCell',row,'EUId');
				<c:choose>
					<c:when
					test='${requestScope.requestContextAttribute.locale.language == "ar"}'>
					var userName = $('#grid').jqGrid('getCell',row,'UNameArb');
					</c:when>
					<c:otherwise>
						var userName = $('#grid').jqGrid('getCell',row,'UNameEng');
					</c:otherwise>
				</c:choose>				
				if(userid != ''){
					var confirmMsg = '<spring:message code="user.reset.password.confirm" />'.replace('###', userName);
					jConfirm(confirmMsg,'<spring:message code="label.button.reset.password" />',function(result){
						if(result) {
							$.ajax({
								type : "POST",
								url : "user/general/manage/resetpassword?userid="
										+ userid,
								cache : false,
								contentType : "application/html",
								dataType : "html",
								success : function(result) {
									jAlert('info',result,'<spring:message code="label.button.reset.password" />');
								}
							});
						}
					});
				}
			}
		}		
		
		});
	
					
	
	
</script>
<%
	if (session.getAttribute(ConstantsAdmin.SUCCESS_PARAM) != null) {
%>
<script type="text/javascript">
				$(document)
						.ready(
								function() {
									jAlert(
											'success','<%=session.getAttribute(ConstantsAdmin.SUCCESS_PARAM)%>',
											'<spring:message code="msg.success" />');
								});
			</script>
<%
	session.removeAttribute(ConstantsAdmin.SUCCESS_PARAM);
	}
%>
<div id="container" dir='<spring:message code="page.dir"/>'
	align='<spring:message code="page.align"/>'>
	<spring:hasBindErrors
		name="<%=ConstantsAdmin.ADMIN_UPDATE_USER_MODEL_KEY %>">
		<script type="text/javascript">
	$(document).ready(
			function() {
				jAlert('error', '<li><form:errors path="*" delimiter="<li>"/>',
						'<spring:message code="label.errormessage" />');
			});
</script>
	</spring:hasBindErrors>



	<div id="search"></div>
	<table id="grid">
	</table>
	<span id="pager"></span>



</div>